#include "httplib.h"
using namespace httplib;
void Hello(const Request &req, Response &res)
{
    res.set_content("Hello World!", "text/plain");
    res.status = 200;

}
void Numbers(const Request &req, Response &res)
{
    auto numbers = req.matches[0];
    res.set_content(numbers, "text/plain");
    res.status = 200;
}
void Multipart(const Request &req, Response &res)
{
    auto ret = req.has_file("file");
    if(ret == false)
    {
        std::cout << "not file upload" << std::endl;
        res.status = 400;
        return;
    }
    const auto& file = req.get_file_value("file");
    res.body.clear();
    res.body = file.filename;
    res.body += "\n";
    res.body += file.content;
    res.set_header("Content-Type", "text/plain");
    res.status = 200;

    return;
}
int main()
{
    
    Server svr;
    svr.Get("/hi", Hello);
    svr.Get(R"(/numbers/(\d+))", Numbers);
    svr.Post("/multipart", Multipart);
    svr.listen("0.0.0.0", 9090);

    return 0;
}